package com.example.demo08;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class PageListPage extends ListFragment {
	
	final String[] ITEMS = {
			"SDObservePage", "RunningProcessPage", "LoginPage", "InfoPage",
			"DrawPage", "ExecPage", "WebPage", "InputPage", "MemInfoPage",
			"CryptPage", "UsbPage", "WifiPage", "TetherPage"
		};

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, ITEMS));
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		try {
			Class<?> cls = Class.forName("com.example.demo08." + ITEMS[position]);
			
			 FragmentTransaction ft = getFragmentManager().beginTransaction();
		        ft.replace(R.id.content, (Fragment) cls.newInstance());
		        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
		        ft.addToBackStack(null);
		        ft.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
